<?php

  class DashangAction extends CommonAction{
  
    public function index(){
	
	
	  $where['uid']=array('eq',session('did'));
	  $where['status']=array('eq','1');
	  $where['kouliang']=array('neq','1');
	
	  $re= $this->page('buyer',10,'id desc',$where);
	  
	  $i=-1;
	  
	  foreach($re as $v){
	  
	    $i++;
		
		$pianku=M('pianku')->where('id="%s"',$v['vid'])->find();
		
		//dump($pianku);
		
		$re[$i]['title']=$pianku['title'];
		
		
		
		
	  
	  }
	  
	  $today=strtotime(date('Y-m-d'));
	  
	  $where['time']=array('gt',$today);
	  
	  $t=M('buyer')->where($where)->select();
	  //dump(M('buyer')->getlastsql());
	  
	  $todaymoney=0;
	  
	  foreach($t as $v){
	  
	    $todaymoney+=$v['money'];
	  
	  }
	  
	  $this->todaymoney=$todaymoney;
	  
	  
	  
	  
	  
	  //今日返佣
	  $f['time']=array('gt',$today);
	  $f['status']=array('eq','1');
	  $f['shoufanyongid']=array('eq',session('did'));
	  $t=M('tixian')->where($where)->select();
	  //dump(M('buyer')->getlastsql());
	  
	  $todayfanyong=0;
	  
	  foreach($t as $v){
	  
	    $todayfanyong+=$v['yongjin'];
		
		
	  
	  }
	  
	  $this->todayfanyong=$todayfanyong;
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  $this->re=$re;
	
	  $this->display();
	
	}
	
	
	public function fanyong(){
	
	
	  $where['bid']=array('eq',session('did'));
	  
	  $where['status']=array('eq','1');
	  
	  $re=$this->page('fanli','10','id desc',$where);
	  
	  $i=-1;
	  
	  foreach($re as $v){
	  
	  $i++;
	  
	  $user=M('dailiuser')->where('id="%s"',$v['fid'])->find();
	  
	  $re[$i]['username']=$user['username'];
	  
	  
	  $pianku=M('pianku')->where('id="%s"',$v['vid'])->find();
	  
	  $re[$i]['title']=$pianku['title'];
	  
	  }
	  
	  
	  
	  $today=strtotime(date(Ymd));
	  
	  $where['time']=array('gt',$today);
	  
	  $jinri=M('fanli')->where($where)->select();
	  
	  
	  $money=0;
	  
	  foreach($jinri as $v){
	  
	    $money+=$v['money'];
	  
	  }
	  
	  $this->money=$money;
	  
      $this->re=$re;
	  $this->display();
	
	 
	
	}
  
  
  }